package com.zhuss.advice.processor;

import com.zhuss.advice.db.dao.ext.ComplaintSonDao;
import com.zhuss.bean.bo.core.upload.DownloadBo;
import com.zhuss.bean.vo.advice.complaintSon.ListComplaintSonVo;
import com.zhuss.bean.vo.core.upload.DownloadVo;
import com.zhuss.common.Processor;
import com.zhuss.exception.WpsException;
import com.zhuss.exception.ExceptionCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: zhushanshuo
 * @Date: 2020/4/13 19:36
 */
@Component("complaintSonRead")
public class ComplaintSonRead {

    @Autowired
    private ComplaintSonDao complaintSonDao;

    @Autowired
    @Qualifier("downloadProcessor")
    private Processor<DownloadVo, DownloadBo> downloadProcessor;

    /**
     * 详情
     * @throws WpsException
     */
    public Object detail(Long complaintId) throws WpsException {
        List<ListComplaintSonVo> result = complaintSonDao.detail(complaintId);
        DownloadBo downloadBo = new DownloadBo();
        for (ListComplaintSonVo vo:result){
            downloadBo.setKey(vo.getSonKey());
            DownloadVo downloadVo = downloadProcessor.process(downloadBo);
            vo.setSonUrl(downloadVo.getUrl());
        }
        if (result == null) {
            throw new WpsException(ExceptionCode.数据不存在);
        }
        return result;
    }
}
